﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class pro_mis_weight_compare2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MasApp.BLL.Check.CheckLogin();
            if (Session["currentweightmissionid"] != null && Request.QueryString["ruleid"]!=null)
            {
                int weightmissionid = Convert.ToInt32(Session["currentweightmissionid"].ToString());
                int ruleid = Convert.ToInt32(Request.QueryString["ruleid"].ToString());
                HyperLink1.NavigateUrl = "editweight2.aspx?ruleid=" + ruleid.ToString();

                for (int ii = 0; ii < GridView1.Rows.Count - 1; ii++)
                {
                    Label lb = (Label)GridView1.Rows[ii].FindControl("Label3");
                    lb.Text = "指标序号【" + ((Label)GridView1.Rows[ii].FindControl("Label4")).Text + "】相对于序号【" + ((Label)GridView1.Rows[ii + 1].FindControl("Label4")).Text + "】比较为：";
                }
                if (MasApp.BLL.Search.SearchIndicatorNumber(ruleid) > 0)
                {
                    DropDownList ddl = (DropDownList)GridView1.Rows[GridView1.Rows.Count - 1].FindControl("DropDownList1");
                    ddl.Visible = false;
                    Label llb = (Label)GridView1.Rows[GridView1.Rows.Count - 1].FindControl("Label3");
                    llb.Visible = false;
                }
            }
            else
            {
                MasApp.BLL.ResponseHelper.alert("非法操作", "../mislist.aspx");
            }
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["currentweightmissionid"] != null && Request.QueryString["ruleid"] != null)
        {
            int weightmissionid = int.Parse(Session["currentweightmissionid"].ToString());
            //序关系法计算最后一个权重为Wn
            //定义y1,y2,y.....,yn中的n
            int n = GridView1.Rows.Count;
            //(1+ENrt)-1中的(1+ENrt)
            float sum = 1.0F;
            for (int t = 2; t <= n; t++)
            {
                float value = 1.0F;
                for (int i = t; i <= n; i++)
                {
                    DropDownList ddl = (DropDownList)GridView1.Rows[i - 2].FindControl("DropDownList1");
                    value *= Convert.ToSingle(ddl.SelectedValue);
                }
                sum += value;
            }
            //定义Wn
            float Wn = 1 / sum;
            //更新被初始化的权值
            MasApp.Model.weight we = new MasApp.Model.weight();
            we.Elementtype = "指标";
            we.Weightmissionid = weightmissionid;
            //更新最后一个权值
            we.Elementid = Convert.ToInt32(((Label)GridView1.Rows[n - 1].FindControl("Label1")).Text);
            we.Weightvalue = Convert.ToSingle(Wn.ToString("F4"));
            MasApp.BLL.Update.UpdateWeight(we);
            //更新其他初始化的权值
            for (int k = n - 2; k >= 0; k--)
            {
                we.Elementid = Convert.ToInt32(((Label)GridView1.Rows[k].FindControl("Label1")).Text);
                we.Weightvalue *= Convert.ToSingle(((DropDownList)GridView1.Rows[k].FindControl("DropDownList1")).SelectedValue);
                we.Weightvalue = Convert.ToSingle(we.Weightvalue.ToString("F4"));
                MasApp.BLL.Update.UpdateWeight(we);
            }
            MasApp.BLL.ResponseHelper.alert("评权成功", "compare2.aspx?ruleid=" + Request.QueryString["ruleid"].ToString());
        }
        else
        {
            MasApp.BLL.ResponseHelper.alert("非法链接，请检查您的登录状态！", "../mislist.aspx");
        }
    }
}